const { defineConfig } = require('@vue/cli-service')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const webpack = require('webpack')
const path = require('path')

module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    plugins: [
      new CopyWebpackPlugin({
        patterns: [
          { from: path.join(path.dirname(require.resolve('cesium/package.json')), 'Build/Cesium/Workers'), to: 'Workers' },
          { from: path.join(path.dirname(require.resolve('cesium/package.json')), 'Build/Cesium/ThirdParty/Workers'), to: 'ThirdParty/Workers' },
          { from: path.join(path.dirname(require.resolve('cesium/package.json')), 'Build/Cesium/Assets'), to: 'Assets' },
          { from: path.join(path.dirname(require.resolve('cesium/package.json')), 'Build/Cesium/Widgets'), to: 'Widgets' }
        ]
      }),
      new webpack.DefinePlugin({
        CESIUM_BASE_URL: JSON.stringify('/'),
      })
    ],
    module: {
      unknownContextCritical: false
    }
  },
  devServer: {
    port: 8081,
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        secure: false
      }
    }
  }
})
